import React from 'react';
import {Menu, Icon} from 'antd';
import {Link} from 'react-router-dom';

const renderMenuItem = item => ( // item.route 菜单单独跳转的路由
  <Menu.Item
    key={item.key}
  >
    <Link to={item.route || item.key}>
      {item.icon && <Icon type={item.icon}/>}
      <span className="nav-text">{item.title}</span>
    </Link>
  </Menu.Item>
);


export default ({menus, ...props}) => {
  const selectedKeys = props.selectedKeys;
  return menus.map(item => {
    if (item.key === selectedKeys.join('')) {
      return (
        <Menu
          key={item.key}
          {...props}>
          {item && item.subs && item.subs.map(item => renderMenuItem(item)
          )}
        </Menu>
      );
    }
  })

}
